package com.app.utill;

import java.util.List;

/**
 * 分页工具类
 */
public class PageBean<T> {

    // 当前页
    private Integer currentPage;
    // 总页数
    private Integer totalPage;
    // 总记录数
    private Integer totalCount;
    // 每页显示多少条数据
    private Integer pageSize;
    // 查询到的数据 T:任意类型
    private List<T> result;

    // 起始下标
    private Integer startIndex;

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getTotalPage() {
        // 计算总页数   totalCount / pageSize
        return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getResult() {
        return result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }

    /**
     * 获取起始页
     * @return
     */
    public Integer getStartIndex() {
        // 公式: (currentPage -1 ) * pageSize

        return (currentPage -1 ) * pageSize;
    }

    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }
}
